<?php
require_once 'controllers/controller.php';
require_once 'models/user_manager.php';
require_once 'models/user.php';

class controller_user extends Controller
{
	protected $_user;
	
	public function __construct() {
		parent::__construct();
		$this->_user = new user_manager($this->_db);
	}
	
	public function hello() {
		$_SESSION['message'] = 'hello world !';
	}
	
	public function login() {
		$u = new user(array(
				"login" => $_POST['login'],
				"password" => sha1($_POST['password'])));
		if($this->_user->is_admin($u)) {
			$_SESSION['isAdmin'] = true;
			$_SESSION['user'] = $u->get_login();
			$_SESSION['message'] = 'Connexion réussie';
		}
		else $_SESSION['message'] =  'Identifiant ou mot de passe incorrect';
		
		header('Location: ?section=accueil&action=show');
		exit();
	}
	
	public function logout() {
		unset($_SESSION['isAdmin']);
		unset($_SESSION['user']);
		
		header('Location: ?section=accueil&action=show');
		exit();
	}
}
?>